package com.soul.dubbo.api.db;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.soul.dubbo.api.mapper.BlackListApiMapper;
import com.soul.model.db.BlackList;
import com.soul.model.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author mdoya
 * @version 1.0
 * @description:
 */
@Slf4j
@DubboService
public class BlackListApiImpl implements BlackListApi{

    @Autowired
    private BlackListApiMapper blackListApiMapper;

    /**
     * 根据用户id查询被拉黑名单用户id
     * @param userId 用户id
     * @return
     */
    @Override
    public PageResult<BlackList> findBlacklistBatchIds(Long userId, Long page, Long pagesize) {
        IPage<BlackList> blackListPage = new Page<>(page,pagesize);
        LambdaQueryWrapper<BlackList> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(BlackList::getUserId,userId);
        blackListApiMapper.selectPage(blackListPage,lambdaQueryWrapper);
        // 封装数据
        return new PageResult<>(blackListPage.getTotal(),pagesize,blackListPage.getPages(),page,blackListPage.getRecords());
    }

    /**
     * 黑名单 - 移除
     *
     * @param blackList 黑名单用户id和用户id
     * @return
     */
    @Override
    public void deleteBlackByUid(BlackList blackList) {
        LambdaQueryWrapper<BlackList> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(BlackList::getUserId,blackList.getUserId());
        lambdaQueryWrapper.eq(BlackList::getBlackUserId,blackList.getBlackUserId());
        blackListApiMapper.delete(lambdaQueryWrapper);
    }
}
